import 'package:flutter/material.dart';
import 'package:proj_sfv/http/requests.dart';

class VideoEditDialog extends StatefulWidget {
  final String videoName;
  final String videoDesc;
  final String videoCoverUrl;
  final String videoUrl;
  VideoEditDialog(
      {Key key,
        this.videoName,
        this.videoDesc,
        this.videoCoverUrl,
        this.videoUrl,
      })
      : super(key: key);

  @override
  _VideoEditDialogState createState() => _VideoEditDialogState();
}

class _VideoEditDialogState extends State<VideoEditDialog> {
  TextEditingController _nameController;
  TextEditingController _descController;

  @override
  void initState() {
    super.initState();
    _nameController = TextEditingController(text: widget.videoName);
    _descController = TextEditingController(text: widget.videoDesc);
  }

  @override
  void dispose() {
    _nameController.dispose();
    _descController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    print(widget.videoCoverUrl);
    return AlertDialog(
      title: Text('修改视频信息'),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Image.network(
            widget.videoCoverUrl,
            height: 150,
          ),
          SizedBox(height: 16),
          TextField(
            controller: _nameController,
            decoration: InputDecoration(
              labelText: '名称',
              hintText: '请输入视频名称',
            ),
          ),
          TextField(
            controller: _descController,
            decoration: InputDecoration(
              labelText: '描述',
              hintText: '请输入视频描述',
            ),
          ),
        ],
      ),
      actions: [
        FlatButton(
          child: Text('取消'),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        FlatButton(
          child: Text('保存'),
          onPressed: () {
            // 保存视频信息
            final String videoName = _nameController.text;
            final String videoDesc = _descController.text;
            print('确认 $videoName, $videoDesc');
            Navigator.pop(context, {
              'videoName': videoName,
              'videoDesc': videoDesc,
            });
          },
        ),
      ],
    );
  }
}
